-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
switch from source-map-support to @cspotcode/source-map-support #12786
base: main
Are you sure you want to change the base?
Conversation
Oops, I accidentally submitted this before finishing running tests locally. Test failures are not intentional; I'll try to figure out what's going on. |
432bfa1
to
62dcc9c
Compare
Might be #9147 |
Is there a way to attach a debugger to some of these tests, to step through what's happening? The build process and test suite bootstrapping are quite complex. I've tried opening |
If I'm reading that issue correctly, jest is relying on incorrect stack traces, ones that do not match V8 / node's behavior? |
essentially, yeah. I haven't bothered to attempt to work around it yet, but it might be time now. Should do that first, before landing this PR. Semi related: #10633, facebook/react#20026 |
As long as you run a single test, debugging should work perfectly fine. Multiple tests spawns processes which at least chrome debugger has issues hitting. Can add |
I've updated the snapshots in #9147, might be interesting to apply this diff on top to see if the stacks then agree |
…potcode-source-map-support
one single change, which seems sorta reasonable? |
There was another test failure where jest was expecting |
Taking a look at #10633, this PR (or rather #9147), but this doesn't fix it makes the stack trace wrong. // hubba.test.js
function BadCode() {
throw new Error('noo');
}
function run(fn) {
fn();
}
run(BadCode);
If I run the same test on main $ yarn jest hubba
FAIL ./hubba.test.js
● Test suite failed to run
noo
1 | function BadCode() {
> 2 | throw new Error('noo');
| ^
3 | }
4 |
5 | function run(fn) {
at BadCode (hubba.test.js:2:9)
at fn (hubba.test.js:6:3)
at Object.run (hubba.test.js:9:1)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.468 s
Ran all test suites matching /hubba/i. Note that it's also correct if I disable code transformation (meaning no source map) or just remove the |
Yeah, might be a bug in Babel actually. The code produced by "use strict";
function BadCode() {
throw new Error('noo');
}
function run(fn) {
fn();
}
run(BadCode);
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJCYWRDb2RlIiwiRXJyb3IiLCJydW4iLCJmbiJdLCJzb3VyY2VzIjpbImh1YmJhLnRlc3QuanMiXSwic291cmNlc0NvbnRlbnQiOlsiZnVuY3Rpb24gQmFkQ29kZSgpIHtcbiAgdGhyb3cgbmV3IEVycm9yKCdub28nKTtcbn1cblxuZnVuY3Rpb24gcnVuKGZuKSB7XG4gIGZuKCk7XG59XG5cbnJ1bihCYWRDb2RlKTtcbiJdLCJtYXBwaW5ncyI6Ijs7QUFBQSxTQUFTQSxPQUFULEdBQW1CO0VBQ2pCLE1BQU0sSUFBSUMsS0FBSixDQUFVLEtBQVYsQ0FBTjtBQUNEOztBQUVELFNBQVNDLEdBQVQsQ0FBYUMsRUFBYixFQUFpQjtFQUNmQSxFQUFFO0FBQ0g7O0FBRURELEdBQUcsQ0FBQ0YsT0FBRCxDQUFIIn0= If I run that file with node $ node -v
v16.15.0
$ node hubba2.js
/Users/simen/repos/jest/hubba2.js:4
throw new Error('noo');
^
Error: noo
at BadCode (/Users/simen/repos/jest/hubba2.js:4:9)
at run (/Users/simen/repos/jest/hubba2.js:8:3)
at Object.<anonymous> (/Users/simen/repos/jest/hubba2.js:11:1)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
$ node --enable-source-maps hubba2.js
/Users/simen/repos/jest/hubba.test.js:2
throw new Error('noo');
^
Error: noo
at fn (/Users/simen/repos/jest/hubba.test.js:2:9)
at run (/Users/simen/repos/jest/hubba.test.js:6:3)
at Object.<anonymous> (/Users/simen/repos/jest/hubba.test.js:9:1)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 The interesting part is the second one, running node with @jridgewell would you be able to comment on this? |
I noticed the package.json version declaration was |
@cspotcode caret generally, it is locked due the the issue with names I commented about above 🙂 |
Hmm, the flag in node is supposed to come from chromium: nodejs/node#29564 EDIT: Sorry @cspotcode, it's unlikely this has anything to do with your PR, but I do think it's blocked by it |
What's the likely culprit? Does this still seem like a flaw in the sourcemaps coming from babel? Is jest currently relying on a bug in the old source-map-support implementation? |
If we keep the callsite fallback enabled by default, should we add an optional flag to disable that behavior? @SimenB will that work for jest? |
That sounds very reasonable! |
I tried teaching source-map-support to map names at In this example:
The first stack frame's This example is great, because it shows how bad it can be to attempt these imperfect sourcemap checks. In the examples we looked at several days ago, we were mapping to the name of a function at its callsite, not its declared name. Both names referred to the same function. So it was imperfect, but semantically it sorta made sense. But today's example is much worst: we are mapping to the name of an entirely different function. This isn't merely imperfect, it's flat-out wrong and misleading. The fix is: never attempt to map names at the "enclosing" position. The sourcemap spec, as it is today, can't do that. |
I've updated this pull request to use a pre-built tarball of cspotcode/node-source-map-support#41 because I don't want to publish to npm till it has passed all code reviews, and because trying to use a git dependency was failing some yarn integrity checks on CI. Here is the diff of my changes against #9147 |
Thanks @cspotcode! I'm still unsure if this is safe to land due to the naming error - for better or worse the current stack traces seems more useful to me, even if the new stacks are more correct. "sourcemap doesn't support this" is an unsatisfying answer when the current behavior of Jest does not have the issue (although it has other issues). Not sure what the best tradeoff here is... And regardless of the stack itself, the potential performance benefit of this migration is appealing, so that alone might be worth it (although I've not run any sort of benchmarks). |
Yeah, that's fair, though I still think jest needs to align with the JS language and find a way to convey that useful information with accurate stack traces. When I talked about avoiding the enclosing position lookup, jest already does not do that. So you're not actually losing anything there. These changes do not necessarily suppress helpful function names from appearing in stack traces. They merely move which stack frame they appear on. For example:
In this example, we'll still see
Another hypothetical example: when jest says |
Node's implementation is largely my best guess at what would be a good user experience. If there's consensus in a large community like Jest, that the behavior in aside... I'm also pretty convinced that trying to provide additional context , in the form of a snippet of source code, was a mistake in Node.js' CC: @cspotcode |
For aggressively minified code, source-mapping the callsite name might be better, If the minifier mangled the name. But since minifiers usually don't mangle property names, that is not always true. For un-minified code, the runtime name is likely to be best all the time. Even when the name is changed, it'll typically be something like So that was my thinking: in the majority of cases, source-mapping callsite name is worse than using runtime name. For minified code it's a toss-up which is better; for unminified code, the runtime name is better. And I was thinking specifically about the most likely use-cases. Where we want source-mapped stack traces: testing, debugging, server-side stuff. So minified code is not the norm. In ts-node, the focus is unminified code, since it's TS->JS. I suspect that's usually the focus in jest as well. |
This PR is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
This PR is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
This PR was closed because it has been stalled for 30 days with no activity. Please open a new PR if the issue is still relevant, linking to this one. |
Summary
Per comments here: #12485 (comment)
For a list of fixes and improvements compared to source-map-support:
cspotcode/node-source-map-support#24
Supercedes and closes #12486
Test plan